﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace MyWpf
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        public MainWindow()
        {
            InitializeComponent();
            Current = this;
            this.DataContext = this;
        }


        public static MainWindow Current { get; private set; }

        private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        string _Message = string.Empty;

        public event PropertyChangedEventHandler PropertyChanged;

        public string Message
        {
            get { return _Message; }
            set
            {
                _Message = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.Message)));
            }
        }

        public void ShowError(string msg)
        {
            this.Dispatcher.Invoke(() =>
            {
                Message = msg;
            });
            new Thread(Tick).Start(msg);
        }

        void Tick(object msg)
        {
            Thread.Sleep(2000);
            if (String.Equals(msg, Message))
            {
                this.Dispatcher.Invoke(() =>
                {
                    Message = string.Empty;
                });
            }
        }

        private void Window_MouseMove(object sender, MouseEventArgs e)
        {
            //var p = e.GetPosition(e.Source as FrameworkElement);
            //ShowError($"x:{p.X},y:{p.Y}");
        }
    }
}
